package work.learn.base;

public class StaticInner {
    // 外部类
    public static class OuterStatic {
        private static final String staticVariable = "I'm a static variable from Outer.";
        private String instanceVariable = "I'm an instance variable from Outer.";

        // 静态内部类
        public static class InnerStatic {
            public void innerStaticMethod() {
                // 定义了 static 则可以访问外部的成员, 因为不需要被实例化
                System.out.println(staticVariable);
                // 下面这行代码会报错，静态内部类不能直接访问外部类的实例成员
                // System.out.println(instanceVariable);
            }
        }
    }

    public static class StaticInnerClassDemo {
        public static void main(String[] args) {
            OuterStatic.InnerStatic innerStatic = new OuterStatic.InnerStatic();
            innerStatic.innerStaticMethod();
        }
    }
}
